package com.zhangyan.dynamic;

public enum DBEnums {
    MYSQL("com.mysql.cj.jdbc.Driver"),                // MySQL
    POSTGRESQL("org.postgresql.Driver"),              // PostgreSQL
    ORACLE("oracle.jdbc.driver.OracleDriver"),       // Oracle
    SQL_SERVER("com.microsoft.sqlserver.jdbc.SQLServerDriver"), // SQL Server
    SQLITE("org.sqlite.JDBC"),                         // SQLite
    MARIADB("org.mariadb.jdbc.Driver"),               // MariaDB
    H2("org.h2.Driver"),                              // H2 Database
    DB2("com.ibm.db2.jcc.DB2Driver"),                // IBM DB2
    SYBASE("com.sybase.jdbc4.jdbc.Driver"),          // Sybase
    CASSANDRA("com.datastax.oss.driver.api.core.CqlSession"), // Cassandra
    REDIS("redis.clients.jedis.Jedis"),               // Redis (for Redis connection)
    CLICKHOUSE("com.clickhouse.jdbc.ClickHouseDriver"), // ClickHouse
    TERADATA("com.teradata.jdbc.TeraDriver"),        // Teradata
    HSQLDB("org.hsqldb.jdbcDriver"),                  // HSQLDB
    VERTICA("com.vertica.jdbc.Driver"),               // Vertica
    GREENPLUM("org.greenplum.jdbc.Driver"),           // Greenplum
    COCKROACHDB("org.postgresql.Driver"),             // CockroachDB (uses PostgreSQL driver)
    NEO4J("org.neo4j.jdbc.Driver");                   // Neo4j

    private final String driverClassName;

    DBEnums(String driverClassName) {
        this.driverClassName = driverClassName;
    }

    public String getDriverClassName() {
        return driverClassName;
    }

    public static String getDriverByType(String dbType) {
        if (dbType == null) {
            return null; // or throw an IllegalArgumentException
        }

        // Convert input to uppercase to match enum names
        String dbTypeUpper = dbType.toUpperCase();

        try {
            return DBEnums.valueOf(dbTypeUpper).getDriverClassName();
        } catch (IllegalArgumentException e) {
            // Handle the case where the dbType is not valid
            return null; // or throw a custom exception
        }
    }
}
